﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

//code shared on the wpdevd alias by ???, waiting for the next release of the Toolkit to get an official implementation of the ToggleSwitch

namespace WP7Square.Converters
{

    public class BoolToStringConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType != typeof(string))
                throw new InvalidOperationException("The target must be a string");

            string strReturnString = String.Empty;
            bool boolValue = (bool)value;

            string strParameter = parameter as string;
            if (strParameter != null)
            {
                string[] strValues = strParameter.Split(",".ToCharArray());
                if (strValues.Length == 2)
                {
                    strReturnString = (boolValue == true) ? strValues[0] : strValues[1];
                }
            }

            return strReturnString;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }






    
}
